package com.chekulab.temp.presenter

import com.chekulab.temp.bean.MainResponeBean
import com.chekulab.temp.contract.MainContract
import com.chekulab.temp.model.MainModel
import com.google.gson.Gson
import com.zhy.http.okhttp.callback.StringCallback

import okhttp3.Call

class MainPresenter(internal var view: MainContract.View) {
    internal var model: MainContract.Model

    init {
        model = MainModel()
    }

    fun getStringList() {
        model.apiResponse.execute(object : StringCallback() {
            override fun onError(call: Call, e: Exception, id: Int) {
                view.showMessage(e.message)
            }

            override fun onResponse(response: String, id: Int) {
                val list = Gson().fromJson<Array<MainResponeBean>>(
                    response,
                    Array<MainResponeBean>
                    ::class.java
                )
                var asReversed = list.map({ it.context }).asReversed()
                view.showStringList(asReversed)


            }
        })
    }
}
